package model;

import java.util.ArrayList;

/*
 * The NonProfit class.
 * @author Abdiel Cabrera
 * 
 * This class inherit all fields, getters and setters from its parent
 * class, such as name, userName, password, etc...
 * 
 * Fields added in addition to the parent class: Organization, Balance, 
 * PreviousAuction, CurrentAuction.
 */

/**
 * NonProfit class.
 * 
 * @author Abdiel Cabrera.
 * @version 1.0
 * @date Winter 2014
 */
public class NonProfit extends User {

	// accessLevel: 3- Auction Central Employee
	/** The access level of the NonProfit user. */
	public static final int MY_LEVEL = 3;

	/** The organization of the NonProfit Object. */
	private String my_organization;

	/** The balance of the NonProfit Object. */
	private double my_balance;

	/** A list of auctions (history) */
	private ArrayList<Auction> my_previousAuctions = new ArrayList<Auction>();
	
	/** Current auction of this NonProfit */
	private Auction my_currentAuction;
	
	/** Enum user type */
	private UserTypeEnum my_user_type = UserTypeEnum.UT_NONPROFIT;
	
	/** 
	 * Construct a NonProfit object. 
	 * 
	 * @pre the_first_name != null
	 * @pre the_last_name != null
	 * @pre the_userName != null
	 * @pre the_password != null
	 * @pre the_phone != null
	 * @pre the_address != null
	 * @pre the_email != null
	 * 
	 * @param the_first_name The first name
	 * @param the_last_name The last name
	 * @param the_userName The user name
	 * @param the_password The password
	 * @param the_phone The phone
	 * @param the_address The address
	 * @param the_email The e-mail
	 */
	public NonProfit(String the_first_name, String the_last_name, String the_userName, String the_password,
			String the_phone, Address the_address, String the_email, String the_organization) {
		super(the_first_name, the_last_name, the_userName, the_password, the_phone, the_address, the_email,
				MY_LEVEL);
		my_organization = the_organization;
	}
	
    /**
     * Blocks a NonProfit. 
     */
	public void blockNonProfit() {
		super.setMy_accessLevel(-1);
	}

	/**
	 * Returns the organization of this NonProfit.
	 * 
	 * @return the organization
	 */
	public String getMy_organization() {
		return my_organization;
	}

	/**
	 * Sets the organization of this NonProfit.
	 * 
	 * @pre the_organization != null
	 * @param the_organization the organization to set
	 */
	public void setMy_organization(String the_organization) {
		this.my_organization = the_organization;
	}

	/**
	 * Returns the balance of this NonProfit.
	 * 
	 * @return the balance
	 */
	public double getMy_balance() {
		return my_balance;
	}

	/**
	 * Sets the balance of this NonProfit.
	 * 
	 * @pre the_balance > 0.0
	 * @param the_balance the balance to set
	 */
	public void setMy_balance(double the_balance) {
		this.my_balance = the_balance;
	}

	/**
	 * Submit Payment.
	 * 
	 * @return TRUE if payment Submitted. 
	 *         FALSE otherwise. 
	 */
	public boolean submitPayment() {
		if (super.getMy_accessLevel() == 3) return true; else return false;
	}

	/**
	 * Cancels the current Auction. 
	 */
	public void cancelAuction(){
		my_currentAuction = null;
	}

	/**
	 * Checks and returns the balance of this NonProfit.
	 * 
	 * @return the balance
	 */
	public double checkBalance(){
		return my_balance;
	}

	/**
	 * Returns a list of all the auctions 
	 * this NonProfit has had.
	 * 
	 * @post ArrayList<Auction> != null
	 */
	public ArrayList<Auction> listPreviousAuctions(){
		return my_previousAuctions;
	}

	/**
	 * Return the previous auctions
	 * 
	 * @post ArrayList<Auction> != null
	 * @return the my_previousAuctions
	 */
	public ArrayList<Auction> getMy_previousAuctions() {
		return my_previousAuctions;
	}

	/**
	 * Sets the previous auctions
	 * 
	 * @pre ArrayList<Auction> != null
	 * @param my_previousAuctions the my_previousAuctions to set
	 */
	public void setMy_previousAuctions(ArrayList<Auction> my_previousAuctions) {
		this.my_previousAuctions = my_previousAuctions;
	}

	/**
	 * @return the my_currentAuction
	 */
	public Auction getCurrentAuction() {
		return my_currentAuction;
	}

	/**
	 * Sets my current auction.
	 * 
	 * @pre the_currentAuction != null
	 * @param my_currentAuction the my_currentAuction to set
	 */
	public void setCurrentAuction(Auction the_currentAuction) {
		this.my_currentAuction = the_currentAuction;
	}
	
	/**
	 * Returns the user type.
	 * 
	 * @return the my_user_type
	 */
	public UserTypeEnum get_userType() {
		return my_user_type;
	}
	
	/**
	 * Returns a String representation of the Non-Profit object.
	 * 
	 * @return a String representation.
	 */
	public String toString() {
		return my_first_name + "~" + my_last_name + "~" + my_userName + "~" + my_password
				 + "~" + my_phone + "~addressObject~" + my_email + "~" + my_organization;
	}
}
